import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
// import { SensitiveText } from '#/components/text';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '参观团名称',
  },
  {
    component: 'ExhibitionSelect',
    fieldName: 'exhibitionId',
    label: '所属展会',
  },
  {
    component: 'Select',
    fieldName: 'number',
    label: '届数',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'visitTime',
    label: '参观时间',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_DATE),
    },
  },
  {
    component: 'Select',
    fieldName: 'sendCar',
    label: '是否派车',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
    },
  },
  {
    component: 'UserListSelect',
    fieldName: 'followUpId',
    label: '跟进人',
  },
  {
    component: 'NumberRangeInput',
    fieldName: 'registerGroupNum',
    label: '人员数',
    defaultValue: [undefined, undefined],
  },
  {
    component: 'AddressCascader',
    fieldName: 'addressMap',
    label: '所在地区',
    componentProps: {
      changeOnSelect: true,
    },
    defaultValue: [],
  },
  // {
  //   component: 'RangePicker',
  //   fieldName: 'createTime',
  //   label: '登记日期',
  // },
  // {
  //   component: 'DatePicker',
  //   fieldName: 'createTime',
  //   label: '登记日期',
  //   componentProps: {
  //     format: 'YYYY-MM-DD HH:mm:ss',
  //     showTime: true,
  //     valueFormat: 'YYYY-MM-DD HH:mm:ss',
  //     getPopupContainer,
  //   },
  // },
  {
    component: 'Select',
    fieldName: 'sitStatus',
    label: '到场状态',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.REGISTER_SIT_STATUS, true),
    },
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '参观团名称',
    field: 'name',
    width: 230,
  },
  {
    title: '届数',
    field: 'number',
    width: 100,
  },
  {
    title: '主联系人',
    field: 'masterName',
    width: 120,
  },
  {
    title: '主联系人电话',
    field: 'masterMobile',
    width: 160,
  },
  // {
  //   title: '所在地区',
  //   field: 'address',
  //   width: 200,
  //   visible: false,
  // },
  {
    title: '参观时间',
    field: 'visitTime',
    width: 150,
  },
  {
    title: '人员数',
    field: 'total',
    width: 120,
    slots: { default: 'total' },
  },
  {
    title: '跟进人',
    field: 'followUpName',
    width: 120,
  },
  {
    title: '是否派车',
    field: 'sendCar',
    width: 100,
    slots: {
      default: ({ row }) => {
        return renderDict(row.sendCar, DictEnum.BUSINESS_YES_NO);
      },
    },
  },
  {
    title: '最近联络时间',
    field: 'contactTime',
    width: 180,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '参观团ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '参观团名称',
    fieldName: 'name',
    component: 'CompanySearchInput',
    rules: 'required',
  },
  {
    label: '所属展会',
    fieldName: 'exhibitionId',
    component: 'ExhibitionSelect',
    rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'number',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    label: '届数',
    rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'visitTime',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_DATE),
    },
    label: '参观时间',
    rules: 'selectRequired',
  },
  // {
  //   label: '是否派车',
  //   fieldName: 'sendCar',
  //   component: 'RadioGroup',
  //   componentProps: {
  //     buttonStyle: 'solid',
  //     options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
  //     optionType: 'button',
  //   },
  //   // defaultValue: 0,
  //   rules: 'selectRequired',
  // },
  {
    component: 'CompanyTagSelect',
    fieldName: 'labelIds',
    label: '企业标签',
    defaultValue: [],
    help: '可多选，通过筛选批量设置企业标签',
    // rules: 'selectRequired',
  },
  {
    component: 'AddressCascader',
    fieldName: 'addressMap',
    label: '所在地区',
    defaultValue: [],
    rules: 'selectRequired',
  },
  {
    label: '详细地址',
    fieldName: 'address',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    componentProps: {
      showCount: true,
      maxlength: 100,
    },
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '参观团名称',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '主联系人',
    fieldName: 'masterName',
    copy: true,
  },
  {
    label: '参观时间',
    fieldName: 'visitTime',
    dictEnum: DictEnum.EXHIBITION_DATE,
  },
  {
    label: '团员总数',
    fieldName: 'total',
  },
  {
    label: '到场人数',
    fieldName: 'sitNum',
  },
  {
    label: '跟进人',
    fieldName: 'followUpName',
  },
  {
    label: '是否派车',
    fieldName: 'sendCar',
    dictEnum: DictEnum.BUSINESS_YES_NO,
  },
  {
    label: '最近联络时间',
    fieldName: 'contactTime',
  },
  {
    label: '备注',
    fieldName: 'remark',
  },
];

// 参观团合并
export const mergeSchema: FormSchemaGetter = () => [
  {
    label: '参观团IDS',
    fieldName: 'ids',
    component: 'Select',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    rules: 'selectRequired',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: [],
      optionType: 'button',
    },
    fieldName: 'id',
    label: '合并至',
    help: '请选择一个合并后保留数据的参观团',
    rules: 'selectRequired',
  },
];

// 转移跟进人
export const transferSchema: FormSchemaGetter = () => [
  {
    label: '参观团IDS',
    fieldName: 'ids',
    component: 'Select',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    rules: 'selectRequired',
  },
  {
    component: 'UserListSelect',
    fieldName: 'followUpId',
    label: '跟进人',
    rules: 'selectRequired',
  },
];
